<!doctype html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
  </head>
  <body>
    <main id="webchat"></main>
    <script>
      const {
        WebChat: { testIds }
      } = window;

      run(async function () {
        const { directLine, store } = testHelpers.createDirectLineEmulator();

        WebChat.renderWebChat(
          {
            directLine,
            store
          },
          document.getElementById('webchat')
        );

        await pageConditions.uiConnected();

        await directLine.emulateIncomingActivity({
          entities: [
            {
              '@context': 'https://schema.org',
              '@type': 'VoteAction',
              type: 'https://schema.org/VoteAction',
              actionOption: 'upvote'
            },
            {
              '@context': 'https://schema.org',
              '@type': 'VoteAction',
              type: 'https://schema.org/VoteAction',
              actionOption: 'downvote'
            }
          ],
          text: 'Hello, World!',
          type: 'message'
        });

        await host.snapshot('local');

        const [activityStatus] = pageElements.activityStatuses();
        const buttons = pageElements.allByTestId(testIds.feedbackButton);

        pageElements.sendBoxTextBox().focus();

        await host.sendShiftTab(3);
        await host.sendKeys('ENTER');
        await expect(document.activeElement).toBe(buttons[0]);

        // Wait for 400 ms for the tooltip to show up.
        await new Promise(resolve => setTimeout(resolve, 400));

        await host.snapshot('local');

        await host.sendTab();
        await expect(document.activeElement).toBe(buttons[1]);

        // Wait for 400 ms for the tooltip to show up.
        await new Promise(resolve => setTimeout(resolve, 400));

        await host.snapshot('local');

        await host.sendTab();
        await expect(document.activeElement).toBe(buttons[0]);

        // Wait for 400 ms for the tooltip to show up.
        await new Promise(resolve => setTimeout(resolve, 400));

        await host.snapshot('local');
      });
    </script>
  </body>
</html>
